<template>
  <div class="app-container">
    <div class="custom_card_0" v-show="showSearch">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="收款人" prop="payee">
          <el-input
            v-model="queryParams.payee"
            placeholder="请输入收款人"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="收款账号" prop="paymentAccount">
          <el-input
            v-model="queryParams.paymentAccount"
            placeholder="请输入收款账号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="流水号" prop="serialNumber">
          <el-input
            v-model="queryParams.serialNumber"
            placeholder="请输入流水号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >搜索
          </el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
          </el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="custom_card">
      <el-row :gutter="10" class="mb10">
        <el-col :span="1.5">
          <el-button

            class="sec-plain-btn" size="medium"
            icon="el-icon-download"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['customer:withdrawalRecord:export']"
          >导出
          </el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="withdrawalRecordList" border>
        <el-table-column
          label="申请人姓名"
          min-width="140"
          align="center"
          prop="proposerName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="申请人昵称"
          min-width="140"
          align="center"
          prop="proposerVxName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="申请人手机号"
          min-width="140"
          align="center"
          prop="proposerPhone"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="申请金额"
          min-width="140"
          align="center"
          prop="applyAmount"
          :show-overflow-tooltip="true"
        />

        <el-table-column
          label="申请时间"
          min-width="140"
          align="center"
          prop="applyTime"
          width="180"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="收款人"
          min-width="140"
          align="center"
          prop="payee"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="收款账号"
          min-width="140"
          align="center"
          prop="paymentAccount"
          :show-overflow-tooltip="true"
        />
         <el-table-column
            label="银行名称"
            min-width="140"
            align="center"
            prop="bankName"
            :show-overflow-tooltip="true"
          />
         <el-table-column
            label="支行名称"
            min-width="140"
            align="center"
            prop="branchBankName"
            :show-overflow-tooltip="true"
          />
        <el-table-column
          label="流水号"
          min-width="140"
          align="center"
          prop="serialNumber"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="打款方式"
          min-width="140"
          align="center"
          prop="serialNumber"
        >
        <template slot-scope="scope">
          线下打款
        </template>
        </el-table-column>
        <el-table-column
          min-width="100"
          label="提现状态"
          align="center"
          prop="wthdrawalState"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.withdrawal_status" :value="scope.row.wthdrawalState" />
          </template>
        </el-table-column>
        <!-- <el-table-column label="驳回原因" min-width="140" align="center" prop="dismissReason" />
      <el-table-column label="审核人名称" min-width="140" align="center" prop="auditorName" />
      <el-table-column label="审核时间" min-width="140" align="center" prop="auditorTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditorTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
        <el-table-column
          label="操作人"
          min-width="140"
          align="center"
          prop="operator"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="打款时间"
          align="center"
          prop="paymentTime"
          min-width="180"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="实际提现金额(元)"
          min-width="140"
          align="center"
          prop="realApplyAmout"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="手续费比例(%)"
          min-width="140"
          align="center"
          prop="commission"
          :show-overflow-tooltip="true"
        />

        <el-table-column
          label="备注"
          min-width="140"
          align="center"
          prop="remark"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="操作"
          min-width="140"
          align="center"
          fixed="left"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              v-if="scope.row.wthdrawalState < 3"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >手动打款
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <!-- 添加或修改提现对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px">
      <el-row :gutter="15">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-col :span="12">
            <el-form-item label="申请人姓名" prop="proposerName">
              <el-input
                v-model="form.proposerName"
                placeholder=""
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人昵称" prop="proposerVxName">
              <el-input
                v-model="form.proposerVxName"
                placeholder=""
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人手机号" prop="proposerPhone">
              <el-input
                v-model="form.proposerPhone"
                placeholder=""
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请金额" prop="applyAmount">
              <el-input
                v-model="form.applyAmount"
                placeholder=""
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请时间" prop="applyTime">
              <el-input
                v-model="form.applyTime"
                placeholder=""
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交易渠道" prop="tradingChannel">
              <el-input value="线下转账" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="打款时间" prop="paymentTime">
              <el-date-picker
                clearable
                size="small"
                v-model="form.paymentTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择支付时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行名称" prop="bankName">
              <el-input
                v-model="form.bankName"
                placeholder="银行名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支行名称" prop="branchBankName">
              <el-input
                v-model="form.branchBankName"
                placeholder="支行名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收款人" prop="payee">
              <el-input v-model="form.payee" placeholder="收款人"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收款账号" prop="paymentAccount">
              <el-input
                v-model="form.paymentAccount"
                placeholder="收款账号"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="流水号" prop="serialNumber">
              <el-input
                v-model="form.serialNumber"
                placeholder="请输入流水号"
              />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listWithdrawalRecord,
    getWithdrawalRecord,
    addWithdrawalRecord,
    updateWithdrawalRecord,
    exportWithdrawalRecord,
  } from '@/api/marketing/withdrawalRecord'

  export default {
    name: 'WithdrawalRecord',
    dicts: ['withdrawal_status', 'withdrawal_Way'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 提现表格数据
        withdrawalRecordList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          payee: null,
          paymentAccount: null,
          bankName: null,
          serialNumber: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          bankName: [
            {
              required: true,
              message: '请输入银行名称',
              trigger: 'blur',
            },
          ],
          branchBankName: [
            {
              required: true,
              message: '请输入支行名称',
              trigger: 'blur',
            },
          ],
          serialNumber: [
            {
              required: false,
              message: '请输入流水号',
              trigger: 'blur',
            },
          ],
          payee: [
            {
              required: true,
              message: '请输入收款人',
              trigger: 'blur',
            },
          ],
          paymentAccount: [
            {
              required: true,
              message: '请输入收款账号',
              trigger: 'blur',
            },
          ],
          paymentTime: [
            {
              required: true,
              message: '请选择打款时间',
              trigger: 'blur',
            },
          ],
        },
      }
    },
    filters: {
      typeFilter(val, type) {
        if (val === null) return null
        let data = type.filter((item) => {
          return val == item.value
        })
        if (data.length) {
          return data[0].label
        } else {
          return val
        }
      },
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询提现列表 */
      getList() {
        this.loading = true
        listWithdrawalRecord(this.queryParams).then((response) => {
          this.withdrawalRecordList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          payee: null,
          paymentAccount: null,
          bankName: null,
          serialNumber: null,
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },

      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset()
        const withdrawalRecordId = row.withdrawalRecordId
        getWithdrawalRecord({id: withdrawalRecordId}).then((response) => {
          this.form = response.data
          this.open = true
          this.title = '打款提现'
        })
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            updateWithdrawalRecord(this.form).then((response) => {
              this.$modal.msgSuccess('打款成功')
              this.open = false
              this.getList()
            })
          }
        })
      },

      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams
        this.$modal
          .confirm('是否确认导出所有提现数据项？')
          .then(() => {
            this.exportLoading = true
            return exportWithdrawalRecord(queryParams)
          })
          .then((response) => {
            this.$download.name(response.msg)
            this.exportLoading = false
          })
          .catch(() => {
          })
      },
    },
  }
</script>
